
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <script type="text/javascript" src="/js/jquery-1.11.2.js"></script>

    <script type="text/javascript" src="/js/spf-ig-grid.js"></script>




    <link rel="stylesheet" type="text/css" href="/css/themes/infragistics/infragistics.theme.css">
    <link rel="stylesheet" type="text/css" href="/css/custom/spf.iggrid.theme.css">
    <link rel="stylesheet" type="text/css" href="/css/structure/infragistics.css">

</head>
<body class="no-skin">


<!-- /section:basics/navbar.layout -->
<div id="declareListDiff" id="main-container">


</div>


<script type="text/javascript">



    $("#declareListDiff").spfGrid({
        autoload: true,
        height: $(window).height() - 90,
        url:  'api/customer/pageCustomer',
        disabledColumnMoving: true,


        queryFields: [

            {id: "category"},{id: "keywords"},{id: "bondName"}],

        mtype: 'post',

        columns: [
            {text: '姓名', width: 80, dataIndex: 'name', align: "left",filter: filter.string, sidx: "name",renderer:function(item,list){
                    var name = list.name==null||list.name==""? list.phone: list.name;
                    return "<a style='color:blue' onclick=\"goto('"+name+"',"+list.id+") \" > "+item+"</a>"
                }},

            {
                text: '客户状态',
                width: 120,
                dataIndex: 'categoryStr',
                align: "center",
                sidx: "category",
                filter: filter.string

            },

            {
                text: '手机号',
                width: 150,
                dataIndex: 'phone',
                align: "center",
                sidx: "phone",
                filter: filter.string
            },

            {
                text: '身份证',
                width: 150,
                dataIndex: 'idCard',
                align: "center",
                sidx: "idCard",
                filter: filter.string
            },

            {
                text: '跟进记录',
                width: 550,
                dataIndex: 'followUserName',
                align: "center",
                sidx: "idCard",
//					index: 'followUserName',
                filter: filter.string,
                renderer: function (obj, list) {
                    var rowObject = list.followVOs
                    if(rowObject!=null&&rowObject.length>0){
                        return rowObject[0].description;
                    }else{
                        return ""
                    }
                }
            },

            {
                text: '跟进时间',
                width: 150,
                dataIndex: 'followVOs',
                align: "center",
                sidx: "idCard",

                renderer: function (rowObject, list) {
                    if(rowObject!=null&&rowObject.length>0){
                        return format(rowObject[0].createTime,"yyyy-MM-dd hh:ss:mm");
                    }else{
                        return ""
                    }

                }
            }


//				{
//					text: '名下车',
//					width: 120,
//					dataIndex: 'carVOs',
//					align: "center",
//					renderer: function (rowObject, list) {
//						if(rowObject==null||rowObject.length==0) return "无";
//
//						var result ="";
//						var i=0
//						$(rowObject).each(function(){
//							if(i==0){
//								result =this.carName
//							}else{
//								result+=","+this.carName
//							}
//							i++;
//
//						})
//						return result;
//
//					}
//
//
//				},{
//					text: '名下保单',
//					width: 120,
//					dataIndex: 'policyVOs',
//					align: "center",
//					renderer: function (rowObject, list) {
//						if(rowObject==null||rowObject.length==0) return "无";
//						var result ="";
//						var i=0
//						$(rowObject).each(function(){
//							if(i==0){
//								result =this.company
//							}else{
//								result+=","+this.company
//							}
//							i++;
//						})
//						return result;
//					}
//
//
//				},
////				{
////					text: '工作单位',
////					width: 120,
////					dataIndex: 'workTime',
////					align: "center",
////					sidx: "workTime"
////
////				},
////				{
////					text: '营业执照时间',
////					width: 120,
////					dataIndex: 'businessTime',
////					align: "center",
////					sidx: "businessTime"
////
////				},
//				{
//					text: '学历',
//					width: 120,
//					dataIndex: 'education',
//					align: "center",
//					sidx: "education"
//
//				},

            ,{
                text: '销售员',
                width: 120,
                dataIndex: 'bondName',
                align: "center",
                sidx: "education",
                filter: filter.string

            },{
                text: '是否有房产',
                width: 120,
                dataIndex: 'haveHouse',
                align: "center",
                sidx: "haveHouse",
                sortable: false,
                renderer:function(item){
                    if(item==0){
                        return "否";
                    }else{
                        return "是";
                    }
                }
            },
            {
                text: '上班/自雇',
                width: 120,
                dataIndex: 'isFeeWork',
                align: "center",
                sidx: "isFeeWork",
                renderer:function(item){
                    if(item==0){
                        return "上班";
                    }else{
                        return "自雇";
                    }
                }
            },

            {
                text: '备注',
                width: 150,
                dataIndex: 'description',
                align: "description",
                sidx: "description",
                filter: filter.string
            }




        ],
        toolbar: [
            //				{
            //				text: '修改客户状态',
            //				handler: function(rows) {
            //					if(!rows || rows.length == 0){
            //						swal("请选择数据");
            //
            //						return ;
            //					};
            //					var ids=[];
            //					var operator = new Object();
            //					$(rows).each(function(k,v){
            //						ids.push(v.id+"");
            //
            //						operator.ids=ids;
            //					});
            //
            //					openCategoryWindow(operator);
            //
            //				}
            //
            //
            //			},

        {
            text: '删除选中数据',
            btnClass: 'ic-grid-fileout',
            handler: function(rows) {
                if(!rows || rows.length == 0){
                    swal("请选择数据");

                    return ;
                };
                bootbox.confirm("确定要删除吗?", function(result) {
                    if(result) {
                        var ids=[];
                        var operator = new Object();
                        $(rows).each(function(k,v){
                            ids.push(v.id+"");

                            operator.ids=ids;
                        });

                        var  operator = JSON.stringify(operator);
                        $.ajax({
                            url:  "${basePath}api/customer/deleteByBaseIds",
                            type: "POST",
                            dataType: "json",
                            traditional: true,
                            contentType : "application/json",
                            async:false,
                            data: operator,
                            success: function (result) {
                                if(result>0){

                                    swal("删除成功","成功删除"+result+"调数据");

                                }else {
                                    swal("","删除失败");

                                }
                                $("#declareListDiff").spfGrid("refresh");
                            }
                        });

                    }});

            }
        },

                {
                    text: '转入到我的名下',
                    handler: function (rows) {
                        if (!rows || rows.length == 0) {
                            swal("请选择数据");

                            return;
                        }
                        ;
                        var ids = [];
                        var operator = new Object();
                        $(rows).each(function (k, v) {
                            ids.push(v.id + "");

                            operator.ids = ids;
                        });

                        openCategoryWindow(operator);

                    }
                },
   {
        text: '转入到名下销售',
        handler: function(rows) {
            if(!rows || rows.length == 0){
                swal("请选择数据");

                return ;
            };
            var ids=[];
            var operator = new Object();
            $(rows).each(function(k,v){
                ids.push(v.id+"");

                operator.ids=ids;
            });

            trueToUser(operator);

        }


    },

        {
            text: '转出选中数据到公共池',
            handler: function(rows) {
                if(!rows || rows.length == 0){
                    swal("请选择数据");

                    return ;
                };

                bootbox.confirm("确定要转出吗?", function(result) {
                    var category= ["N","Y","S","L","M"]
                    if(result) {
                        var ids=[];
                        var operator = new Object();

                        var flag=false;
                        $(rows).each(function(k,v){

                            if( v.category!=undefined&&category.indexOf(v.category)<0){
                                flag=true;
                            }else {
                                ids.push(v.id + "");
                            }

                        });
                        if(flag){
                            swal("只能转出级别为(N,Y,S,L,M)的客户")

                        }else{
                            operator.ids=ids;

                            var  operator = JSON.stringify(operator);

                            $.ajax({
                                url:  "${basePath}api/customer/removeToPoolByIds",
                                type: "POST",
                                dataType: "json",
                                traditional: true,
                                contentType : "application/json",
                                async:false,
                                data: operator,
                                success: function (result) {
                                    if(result>0) {
                                        swal("", "转出成功"+result+"条记录");

                                    }else{
                                        swal("", "转出失败：原因(客户未完善必填信息或者转入后未添加跟进记录，不能转出公共池（具体请看日志）)");
                                    }
                                    $("#declareListDiff").spfGrid("refresh");
                                }
                            });
                        }

                    }});

            }
        }
        ],
        actionColumn:[

        {
            label:'编辑' ,
            bgColor:actionBgColor.upload ,
            iconCls:'spf-iggrid-icon_edit',
            callBackFn: function (evt, rowObject) {


                if(rowObject.isEdit==0){
                    swal("储备主管不能编辑名下销售的客户");
                    return false;
                }
                var name = rowObject.name==null||rowObject.name==""? rowObject.phone: rowObject.name;
                top.mainFrame.tabAddHandler(rowObject.id,"编辑("+name+")",mainPath + 'customer/goEdit/'+rowObject.id);
            }
        },



        {
            label:'修改客户状态' ,
            bgColor:actionBgColor.upload ,
            iconCls:'spf-iggrid-icon_edit',
            callBackFn: function (evt, rowObject) {
                if(rowObject.isEdit==0){
                    swal("储备主管不能修改名下销售的客户等级");
                    return false;
                }

                var ids=[];
                var operator = new Object();
                ids.push(rowObject.id+"");
                operator.ids=ids;


                openCategoryWindow(operator,rowObject.id);

            }

        },


    {
        label:'查看' ,
            bgColor:actionBgColor.query ,
        iconCls:'spf-iggrid-icon_eyes',
        callBackFn: function (evt, rowObject) {

        var name = rowObject.name==null||rowObject.name==""? rowObject.phone: rowObject.name;
        top.mainFrame.tabAddHandler(rowObject.id,"查看("+name+")", mainPath +'customer/view/'+rowObject.id+"?tagId=z122");

    }
    },

        {
            label:'跟进' ,
            bgColor:actionBgColor.query ,
            iconCls:'spf-iggrid-icon_eyes',
            callBackFn: function (evt, rowObject) {

                var name = rowObject.name==null||rowObject.name==""? rowObject.phone: rowObject.name;
                top.mainFrame.tabAddHandler(rowObject.id,"跟进("+name+")",'customer/follow/'+rowObject.id+"?tagId=z122");

            }
        },


        {
            label:'转入到名下销售' ,
            bgColor:actionBgColor.query ,
            iconCls:'spf-iggrid-icon_eyes',
            callBackFn: function (evt, rowObject) {


                var ids=[];
                var operator = new Object();

                ids.push(rowObject.id+"");


                operator.ids=ids;

                trueToUser(operator);

            }

        },


        {
            label:'转入到名下' ,
            bgColor:actionBgColor.query ,
            iconCls:'spf-iggrid-icon_eyes',
            callBackFn: function (evt, rowObject) {


                var ids=[];
                var operator = new Object();

                ids.push(rowObject.id+"");


                operator.ids=ids;

                operator.userId="${userId}";
                var  param = JSON.stringify(operator);
                if("${userId}"!=""){
                    $.ajax({
                        url:  "${basePath}api/customer/turnCustomersToChildUser",
                        type: "POST",
                        dataType: "json",
                        traditional: true,
                        contentType : "application/json",
                        async:false,
                        data: param,
                        success: function (result) {
                            if(result>0) {
                                swal("转入成功"+result+"条数据");
                            }else if(result==0){
                                swal("转入成功"+result+"条数据,具体原因请查看操作日志");
                            }else if(result==-1){
                                swal("转入失败,销售客户人数已经达到上限");
                            }else{
                                swal("转入失败");
                            }
                            $("#declareListDiff").spfGrid("refresh");
                        }
                    });
                }

            }

        },




        {
            label:'转出到公共池' ,
            bgColor:actionBgColor.query ,
            iconCls:'spf-iggrid-icon_eyes',
            callBackFn: function (evt, rowObject) {
                var category= ["N","Y","S","L","M"]
                bootbox.confirm("确定要转出吗?", function(result) {
                    if(result) {
                        var ids=[];

                        var operator = new Object();

                        if(rowObject.category==undefined||category.indexOf(rowObject.category)>=0){

                            ids.push(rowObject.id+"");
                            operator.ids=ids;

                            var  operator = JSON.stringify(operator);
                            $.ajax({
                                url:  "${basePath}api/customer/removeToPoolByIds",
                                type: "POST",
                                dataType: "json",
                                traditional: true,
                                contentType : "application/json",
                                async:false,
                                data: operator,
                                success: function (result) {
                                    if(result>0) {
                                        swal("", "转出成功"+result+"条记录");

                                    }else{
                                        swal("", "转出失败：原因(客户未完善必填信息或者转入后未添加跟进记录，不能转出公共池（具体请看日志）)");
                                    }
                                    $("#declareListDiff").spfGrid("refresh");
                                }
                            });
                        }else{
                            swal("只能转出级别为(N,Y,S,L,M)的客户")
                        }

                    }});

            }, isShowActionFn: function (rowObject) {
                var category= ["N","Y","S","L","M"]
                if (category.indexOf(rowObject.category)>=0){
                    return true;
                }
                return false;
            }
        }
        </c:if>
        ],
    enableCheckBoxes: true
    });
    var page=${page2}
        $("#declareListDiff").spfGrid("setIndex", page);
    //打开上传excel页面
    function fromExcel(){
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag=true;
        diag.Title ="EXCEL 导入批量导入客户";
        diag.URL = '<%=basePath%>customer/goUploadExcel.do';
        diag.Width = 300;
        diag.Height = 150;
        diag.CancelEvent = function(){ //关闭事件
            if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
                var successCount = $(diag.innerFrame.contentWindow.document.getElementById('successCount')).val();
                var failCont = $(diag.innerFrame.contentWindow.document.getElementById('failCont')).val();
                $("#importCustomer").tips({
                    side:2,
                    msg:'导入成功<br>成功：【'+successCount+'】条 <br> 失败：【'+failCont+'】条',
                    bg:'#AE81FF',

                    time:8
                });
                $("#declareListDiff").spfGrid("refresh");
//					setTimeout("self.location.reload()",200);

            }
            diag.close();
        };
        diag.show();
    }
    //打开绑定用户窗口
    function openCategoryWindow(operator,cusId){

        top.jzts();
        var fees = new Array();
        var diag = new top.Dialog();
        diag.Drag=true;
        diag.Title ="选择客户状态";
        diag.URL = '<%=basePath%>customer/categoryWindow?customerId='+cusId;

        diag.Width = 700;
        diag.Height = 545;
        diag.Modal = true;				//有无遮罩窗口
        diag. ShowMaxButton = true;	//最大化按钮
        diag.ShowMinButton = true;		//最小化按钮
        diag.CancelEvent = function(){ //关闭事件
            if(diag.innerFrame.contentWindow.document.getElementById('zhongxin2').style.display == 'none'){
                var val = $(diag.innerFrame.contentWindow.document.getElementById('customerTypeId')).val();

                var table = $(diag.innerFrame.contentWindow.document.getElementById('feeIndex')).find("table");
                $(table).each(function(){
                    var fee = new Object();

                    fee.interestRate =$(this).find("input[name='interestRate']").val();
                    fee.serviceRate =$(this).find("input[name='serviceRate']").val();
                    fee.serviceStage =$(this).find("select[name='serviceStage']").val();
                    fee.payedFee  =$(this).find("input[name='payedFee']").val();
                    fee.serviceFeeId =$(this).find("input[name='serviceFeeId']").val();
                    fee.payFee  =$(this).find("input[name='payFee']").val();
                    fee.payTime  =$(this).find("input[name='payTime']").val();
                    fees.push(fee);

                })



                if(val!=""){
                    operator.bindingType=val;
                    operator.fees=fees;
                    var  param = JSON.stringify(operator);
                    if(val!=null){
                        $.ajax({
                            url:  "${basePath}api/customer/userBindingType",
                            type: "POST",
                            dataType: "json",
                            traditional: true,
                            contentType : "application/json",
                            async:false,
                            data: param,
                            success: function (result) {
                                swal("修改成功");
                                $("#declareListDiff").spfGrid("refresh");
                            }
                        });
                    }
                }

            }

//				history.go(0);
            diag.close();
        };
        diag.show();
    }
    function format (date,fmt) { //author: meizz
        var date = new Date(date);
        var o = {
            "M+": date.getMonth() + 1, //月份
            "d+": date.getDate(), //日
            "h+": date.getHours(), //小时
            "m+": date.getMinutes(), //分
            "s+": date.getSeconds(), //秒
            "q+": Math.floor((date.getMonth() + 3) / 3) //季度

        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));

        return fmt;
    }

    //打开绑定用户窗口
    function trueToUser(operator){

        top.jzts();
        var diag = new top.Dialog();
        diag.Drag=true;
        diag.Title ="转入客户到名下销售";
        diag.URL = '<%=basePath%>customer/listRebindingUsersForWindow.do';

        diag.Width = 700;
        diag.Height = 545;
        diag.Modal = true;				//有无遮罩窗口
        diag. ShowMaxButton = true;	//最大化按钮
        diag.ShowMinButton = true;		//最小化按钮
        diag.CancelEvent = function(){ //关闭事件
            if(diag.innerFrame.contentWindow.document.getElementById('zhongxin2').style.display == 'none'){
                var val = $(diag.innerFrame.contentWindow.document.getElementById('userId')).val();
                if(val!=""){
                    operator.userId=val;
                    var  param = JSON.stringify(operator);
                    if(val!=null){
                        $.ajax({
                            url:  "${basePath}api/customer/turnCustomersToChildUser",
                            type: "POST",
                            dataType: "json",
                            traditional: true,
                            contentType : "application/json",
                            async:false,
                            data: param,
                            success: function (result) {
                                if(result>0) {
                                    swal("转入成功"+result+"条数据");
                                }else if(result==0){
                                    swal("转入成功"+result+"条数据,具体原因请查看操作日志");
                                }else if(result==-1){
                                    swal("转入失败,销售客户人数已经达到上限");
                                }else{
                                    swal("转入失败");
                                }
                                $("#declareListDiff").spfGrid("refresh");
                            }
                        });
                    }
                }

            }

//				history.go(0);
            diag.close();
        };
        diag.show();
    }
    function goto(name,id){



        top.mainFrame.tabAddHandler(id,"查看("+name+")", mainPath +'customer/view/'+id+"?tagId=z122");


    }


</script>



</body>
</html>